<template>
  <div class="update-birthday">
    <!--
      currentDate 双向绑定了日期选择器
        设置日期选择器的默认值
        同步日期选择器选择的日期
      min-date: 可选的最小日期
      max-date: 可选的最大日期
     -->
    <van-datetime-picker
      v-model="currentDate"
      type="date"
      :min-date="minDate"
      :max-date="maxDate"
      @cancel="$emit('close')"
      @confirm="submit"
    />
  </div>
</template>

<script>
import dayjs from 'dayjs'
import {updateUserProfile} from '@/api/user'
export default {
  name: 'UpdateGender',
  components: {},
  props: {
    birthday:{
      type:String
    }
  },
  data () {
    return {
       minDate: new Date(1900, 0, 1),
       maxDate: new Date(2100,10,1),
       currentDate: new Date(this.birthday)
    }
  },
  methods: {
      async submit(){
    try {
        let birthday = dayjs(this.currentDate).format('YYYY-MM-DD')
        await updateUserProfile({
          birthday
        })
        this.$emit('update:birthday',birthday)
        this.$emit('close')
      } catch (error) {
        this.$toast.fail('修改失败')
      }
   }
  }  
}
</script>

<style scoped lang="less">
</style>